
const dateTool = {
  formatMdd (dateStr) {
    let dateModel = new Date(dateStr)
    return dateModel.getMonth() + 1 + '.' + dateModel.getDate()
  },
  formatyyyyMMdd (dateStr, opts = {}) {
    let dateModel = new Date(dateStr)
    let m = dateModel.getMonth() + 1
    let d = dateModel.getDate()
    const placeHolder = opts.placeholder || '.'
    let str = dateModel.getFullYear() + placeHolder + (m >= 10 ? m : '0' + m) + placeHolder + (d >= 10 ? d : '0' + d)
    return str
  },
  millsecondsToDate (left) {
    let day = Math.floor(left / (1000 * 60 * 60 * 24))
    let hours = Math.floor(
      (left - day * 1000 * 60 * 60 * 24) / (1000 * 60 * 60)
    )
    let minutes = Math.floor(
      (left - day * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60) /
      (1000 * 60)
    )

    let seconds = Math.floor(
      (left -
        day * 1000 * 60 * 60 * 24 -
        hours * 1000 * 60 * 60 -
        minutes * 1000 * 60) /
      1000
    )
  },
  millsecondsToDate (now) {
    let date = new Date(now)
    let y = date.getFullYear() // 年份
    let m = date.getMonth() + 1 // 月份，注意：js里的月要加1
    if (m < 10) {
      m = '0' + m
    }
    let d = date.getDate() // 日
    if (d < 10) {
      d = '0' + d
    }
    let h = date.getHours() // 小时
    if (h < 10) {
      h = '0' + h
    }
    let min = date.getMinutes() // 分钟
    if (min < 10) {
      min = '0' + min
    }
    let s = date.getSeconds() // 秒
    if (s < 10) {
      s = '0' + s
    }
    return y + '-' + m + '-' + d + ' ' + h + ':' + min + ':' + s
  }
}
export default dateTool